package freedoms.yousister.user;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import freedoms.yousister.R;
import freedoms.yousister.vo.Friend;

public class UserListAdapter extends BaseAdapter {

	private List<Friend> friends;
	private int usersCount;
	private LayoutInflater layoutInflater;

	public UserListAdapter(Context context, List<Friend> friends) {
		this.friends = friends;
		this.usersCount = friends.size();
		layoutInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return this.usersCount;
	}

	@Override
	public Object getItem(int position) {
		return friends.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = layoutInflater.inflate(R.layout.userlist_item, null);
			viewHolder.friend_username = (TextView) (convertView.findViewById(R.id.friend_username));
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.friend_username.setText(friends.get(position).getFriend_username());
		return convertView;
	}

	public static class ViewHolder {
		TextView friend_username;
	}
}
